Skip to content

crypto: align WebCrypto error behavior with specs - #65550

Closed
panva wants to merge 3 commits into
nodejs:mainfrom
panva:fix-webcrypto-spec-errors
Closed

crypto: align WebCrypto error behavior with specs#65550
panva wants to merge 3 commits into
nodejs:mainfrom
panva:fix-webcrypto-spec-errors

Conversation

@panva

@panva panva commented Aug 25, 2026

Copy link
Copy Markdown
Member

This aligns three WebCrypto behaviors with their specifications:

  • RSA-PSS verification with an impossible saltLength now resolves false while signing continues to reject with OperationError (WebCrypto, RFC 8017).
  • Exporting a private key as SPKI now rejects with InvalidAccessError, including through wrapKey(), as required by the export steps.
  • JWK imports now validate requested usages before key_ops, so SyntaxError takes precedence when both are invalid (RSA-PSS, ECDSA, ML-KEM).

panva added 3 commits August 25, 2026 22:51
Let OpenSSL handle representable salt lengths so verification of an
impossible length resolves false. Guard values outside the native int32
parameter range to prevent SignJob from silently ignoring them.

Move the digest-size helper next to HKDF, its remaining consumer.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Reject SPKI export of a private asymmetric key with InvalidAccessError
as required by the algorithm export steps. Let wrapKey propagate the
same export failure.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Check requested usages against the JWK public or private key type
before validating key_ops. This preserves the SyntaxError precedence
specified for RSA, EC, CFRG, ML-DSA, and ML-KEM imports.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
@panva panva added the commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. label Aug 25, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Aug 25, 2026
@panva panva added the webcrypto Issues and PRs related to the Web Crypto API. label Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (7aaf9b4) to head (be76256).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #65550   +/-   ##
=======================================
  Coverage   90.13%   90.13%           
=======================================
  Files         751      751           
  Lines      253639   253641    +2     
  Branches    47790    47794    +4     
=======================================
+ Hits       228618   228622    +4     
+ Misses      16264    16258    -6     
- Partials     8757     8761    +4     
Files with missing lines Coverage Δ
lib/internal/crypto/cfrg.js 95.90% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/ec.js 96.91% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/hkdf.js 100.00% <100.00%> (ø)
lib/internal/crypto/ml_dsa.js 97.39% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/ml_kem.js 95.35% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/rsa.js 94.62% <100.00%> (-0.08%) ⬇️
lib/internal/crypto/util.js 97.42% <ø> (+0.31%) ⬆️
lib/internal/crypto/webcrypto.js 97.77% <100.00%> (+<0.01%) ⬆️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@panva panva added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. labels Aug 26, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 26, 2026
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment was marked as outdated.

@panva panva added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2026
@panva panva added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2026
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva panva added the commit-queue PRs queued for automated landing through the Commit Queue. label Aug 27, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 05a8e91...4788fb7

nodejs-github-bot pushed a commit that referenced this pull request Aug 27, 2026
Let OpenSSL handle representable salt lengths so verification of an
impossible length resolves false. Guard values outside the native int32
parameter range to prevent SignJob from silently ignoring them.

Move the digest-size helper next to HKDF, its remaining consumer.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: #65550
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: James M Snell <jasnell@gmail.com>
nodejs-github-bot pushed a commit that referenced this pull request Aug 27, 2026
Reject SPKI export of a private asymmetric key with InvalidAccessError
as required by the algorithm export steps. Let wrapKey propagate the
same export failure.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: #65550
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: James M Snell <jasnell@gmail.com>
nodejs-github-bot pushed a commit that referenced this pull request Aug 27, 2026
Check requested usages against the JWK public or private key type
before validating key_ops. This preserves the SyntaxError precedence
specified for RSA, EC, CFRG, ML-DSA, and ML-KEM imports.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: #65550
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: James M Snell <jasnell@gmail.com>
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Aug 27, 2026
@panva
panva deleted the fix-webcrypto-spec-errors branch August 27, 2026 21:16
aduh95 pushed a commit that referenced this pull request Aug 29, 2026
Let OpenSSL handle representable salt lengths so verification of an
impossible length resolves false. Guard values outside the native int32
parameter range to prevent SignJob from silently ignoring them.

Move the digest-size helper next to HKDF, its remaining consumer.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: #65550
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: James M Snell <jasnell@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 29, 2026
Reject SPKI export of a private asymmetric key with InvalidAccessError
as required by the algorithm export steps. Let wrapKey propagate the
same export failure.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: #65550
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: James M Snell <jasnell@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 29, 2026
Check requested usages against the JWK public or private key type
before validating key_ops. This preserves the SyntaxError precedence
specified for RSA, EC, CFRG, ML-DSA, and ML-KEM imports.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: #65550
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. webcrypto Issues and PRs related to the Web Crypto API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants